<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ page import="com.pptree.vo.Student" %>
<%@ page import="java.text.*" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>表达式语言EL</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  	<%!
  		public static Date format(String source){
  		    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  		    try
  		    {
  		    	return df.parse(source);
  		    }
  		    catch(Exception e){
  		    	return null;
  		    }
  		
  	    }
  	%>
  	
  	<%
  		Student stu1 = new Student("s1000","朱小明",27,format("1990-10-23"));
	  	Student stu2 = new Student("s1001","鲁京",25,format("1992-04-16"));
	  	Student stu3 = new Student("s1002","郭帅",24,format("1994-10-23"));
	  	Student stu4 = new Student("s1003","李晓明",27,format("1990-04-23"));
  		
	  	
	  	List<Student> studentList = new ArrayList<Student>();
	  	studentList.add(stu1);
	  	studentList.add(stu2);
	  	studentList.add(stu3);
	  	studentList.add(stu4);
	  	request.setAttribute("studentList", studentList);
	  	
	  	Set<Student> studentSet = new HashSet<Student>();
	  	studentSet.add(stu1);
	  	studentSet.add(stu2);
	  	studentSet.add(stu3);
	  	studentSet.add(stu4);
	  	request.setAttribute("studentSet", studentSet);
	  	
	  	Map<String,Student> studentMap = new HashMap<String,Student>();
	  	studentMap.put(stu1.getId(),stu1);
	  	studentMap.put(stu2.getId(),stu2);
	  	studentMap.put(stu3.getId(),stu3);
	  	studentMap.put(stu4.getId(),stu4);
	  	request.setAttribute("studentMap", studentMap);
	  	
  	%>
  	
  	<h1>ArrayList</h1>
  	
  	<c:forEach items="${ studentList }" var="student" varStatus="status">
  		    <!--
  		    varStatus:用来表示迭代的状态信息
  		    current：当前这次迭代的（集合中的）项。 

            index：当前这次迭代从0开始的迭代索引。 

            count：当前这次迭代从1开始的迭代计数。 

            first：用来表明当前这轮迭代是否为第一次迭代，该属性为boolean类型。 

            last：用来表明当前这轮迭代是否为最后一次迭代，该属性为boolean类型。  -->
            <c:out value="${ status.current }"></c:out> <br />
            <c:out value="${ status.index }"></c:out><br />
            <c:out value="${ status.count }"></c:out><br />
            <c:out value="${ status.first }"></c:out><br />
            <c:out value="${ status.last }"></c:out><br />
  		<p <c:if test="${status.count % 2 == 1 }">style="background:red;"</c:if>>${ student.id } --- ${ student.name } --- ${ student.age } --- <fmt:formatDate value="${ student.birthday}" pattern="yyyy年MM月dd日"/></p> <br />
  	</c:forEach>
  	
  	
  	<hr />
  	
  	<h1>HashSet</h1>

  <c:forEach items="${ studentSet }" var="student" varStatus="vs">
  		${ student.id } --- ${ student.name } --- ${ student.age } --- <fmt:formatDate value="${ student.birthday}" pattern="yyyy年MM月dd日"/> <br />
  	</c:forEach>
  	
  	
  	<h1>HashMap</h1>

  <c:forEach items="${ studentMap }" var="entry" varStatus="vs">
  		${ entry.value.id } --- ${ entry.value.name } --- ${ entry.value.age } --- <fmt:formatDate value="${ entry.value.birthday}" pattern="yyyy年MM月dd日"/> <br />
  	</c:forEach>
  </body>
</html>
